<template>
  <div class="main-table">
    <Form ref="formRef" :model="form1" :rules="ruleValidate" :label-width="80">
      <Row class="flex space-between">
        <Col span="8 flex">
          <FormItem label="清单流水号" :label-width="100"> </FormItem>
        </Col>
        <Col span="8 flex">
          <FormItem label="定点医疗机构名称" prop="head.hospitalName" :label-width="140">
            <Input v-model="form1.head.hospitalName" @onBlur="changeQc"></Input>
          </FormItem>
        </Col>
        <Col span="8 flex">
          <FormItem label="定点医疗机构代码" prop="head.hospitalCode" :label-width="140">
            <Input v-model="form1.head.hospitalCode"></Input>
          </FormItem>
        </Col>
      </Row>
      <Row style="margin-top: 20px" class="flex space-between">
        <Col span="8 flex">
          <FormItem label="医保结算等级" prop="head.level" :label-width="110">
            <Input v-model="form1.head.level"></Input>
          </FormItem>
        </Col>
        <Col span="8 flex">
          <FormItem label="医保编码" prop="head.insureCode" :label-width="130">
            <Input v-model="form1.head.insureCode"></Input>
          </FormItem>
        </Col>
        <Col span="8 flex">
          <FormItem label="病案号" prop="head.number" :label-width="130">
            <Input v-model="form1.head.number" @onBlur="changeQc('bah', 'head', 'number')"></Input>
          </FormItem>
        </Col>
      </Row>
      <Row style="margin-top: 20px" class="flex ai-center">
        <Col span="8 flex">
          <FormItem label="申报时间" prop="head.declareTime" :label-width="100">
            <DatePicker
              v-model="form1.head.declareTime"
              :format="'yyyy-MM-dd HH:mm:ss'"
              type="datetime"
              @on-change="form1.head.declareTime = $event"
            />
          </FormItem>
        </Col>
      </Row>
      <div class="title1">一、基本信息</div>

      <Row style="margin-top: 20px" class="flex space-between ai-center">
        <Col span="6 flex">
          <FormItem label="姓名" prop="basicInfo.realName">
            <Input v-model="form1.basicInfo.realName" @onBlur="changeQc"></Input>
          </FormItem>
        </Col>
        <Col span="8 flex">
          <FormItem label="性别" direction="vertical" prop="basicInfo.sex">
            <RadioGroup v-model="form1.basicInfo.sex" @onChange="changeGroup('sex')">
              <Radio label="0">
                <span>未知的性别</span>
              </Radio>
              <Radio label="1">
                <span>男</span>
              </Radio>
              <Radio label="2">
                <span>女</span>
              </Radio>
              <Radio label="9">
                <span>未说明的性别</span>
              </Radio>
            </RadioGroup>
          </FormItem>
        </Col>
        <Col span="6 flex">
          <FormItem label="出生日期" prop="basicInfo.csrq">
            <DatePicker
              v-model="form1.basicInfo.csrq"
              type="date"
              format="yyyy-MM-dd"
              @on-change="changeBirthday"
            />
          </FormItem>
        </Col>
        <Col span="4 flex">
          <FormItem label="年龄" prop="basicInfo.age">
            <Input v-model="form1.basicInfo.age" @onBlur="changeGroup"></Input>
          </FormItem>
        </Col>
      </Row>

      <Row style="margin-top: 20px" class="flex space-between ai-center">
        <Col span="8 flex">
          <FormItem label="国籍" prop="basicInfo.coutry">
            <Select filterable v-model="form1.basicInfo.coutry" @onChange="changeQc">
              <Option v-for="item in gjEnum" :value="item.label" :key="item.value">
                {{ item.value }}
              </Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="8 flex ai-center">
          <FormItem label="（年龄不足1周岁） 年龄" prop="basicInfo.age_New" :label-width="180">
            <InputNumber
              type="number"
              controls-outside
              :min="0"
              :max="365"
              v-model="form1.basicInfo.age_New"
              @onBlur="changeGroup('', true)"
            ></InputNumber> </FormItem
          >天
        </Col>

        <Col span="8 flex">
          <FormItem label="民族" prop="basicInfo.nation">
            <Select filterable v-model="form1.basicInfo.nation" @onChange="changeQc">
              <Option v-for="item in mzEnum" :value="item.label" :key="item.value">
                {{ item.value }}
              </Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row style="margin-top: 20px" class="flex space-between">
        <Col span="8 flex">
          <FormItem label="患者证件类别" prop="basicInfo.certType" :label-width="130">
            <Select filterable v-model="form1.basicInfo.certType">
              <Option v-for="item in certTypeEnum" :value="item.label" :key="item.value">
                {{ item.value }}
              </Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="16 flex ai-center">
          <FormItem label="患者证件号码" prop="basicInfo.certNo" :label-width="130">
            <Input v-model="form1.basicInfo.certNo" @onBlur="changeQc"></Input>
          </FormItem>
        </Col>
      </Row>

      <Row style="margin-top: 20px" class="flex space-between">
        <Col span="8 flex">
          <FormItem label="职业" prop="basicInfo.jobType">
            <Select filterable v-model="form1.basicInfo.jobType" @onChange="changeQc">
              <Option v-for="item in zyEnum" :value="item.label" :key="item.value">
                {{ item.value }}
              </Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="16 flex ai-center">
          <FormItem label="现住址" prop="basicInfo.homeAddress" :label-width="100">
            <Input v-model="form1.basicInfo.homeAddress" @onBlur="changeQc"></Input>
          </FormItem>
        </Col>
      </Row>

      <Row style="margin-top: 20px" class="flex space-between">
        <Col span="8 flex ai-center">
          <FormItem label="工作单位及地址" prop="basicInfo.jobName" :label-width="150">
            <Input v-model="form1.basicInfo.jobName"></Input>
          </FormItem>
        </Col>

        <Col span="8 flex ai-center">
          <FormItem label="单位电话" prop="basicInfo.jobPhone" :label-width="100">
            <Input v-model="form1.basicInfo.jobPhone" @onBlur="changeQc"></Input>
          </FormItem>
        </Col>

        <Col span="8 flex ai-center">
          <FormItem label="邮编" prop="basicInfo.jobPostCode">
            <Input v-model="form1.basicInfo.jobPostCode" @onBlur="changeQc"></Input>
          </FormItem>
        </Col>
      </Row>

      <Row style="margin-top: 20px" class="flex space-between">
        <Col span="6 flex ai-center">
          <FormItem label="联系人姓名" prop="basicInfo.contactName" :label-width="100">
            <Input v-model="form1.basicInfo.contactName" @onBlur="changeQc"></Input>
          </FormItem>
        </Col>

        <Col span="6 flex">
          <FormItem label="关系" prop="basicInfo.contactType">
            <Select filterable v-model="form1.basicInfo.contactType" @onChange="changeQc">
              <Option v-for="item in gxEnum" :value="item.label" :key="item.value">
                {{ item.value }}
              </Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="6 flex ai-center">
          <FormItem label="地址" prop="basicInfo.contactAddress" :label-width="100">
            <Input v-model="form1.basicInfo.contactAddress" @onBlur="changeQc"></Input>
          </FormItem>
        </Col>

        <Col span="6 flex ai-center">
          <FormItem label="电话" prop="basicInfo.contactPhone" :label-width="100">
            <Input v-model="form1.basicInfo.contactPhone" @onBlur="changeQc"></Input>
          </FormItem>
        </Col>
      </Row>

      <Row style="margin-top: 20px" class="flex space-between">
        <Col span="8 flex">
          <FormItem label="医保类型" prop="basicInfo.insureType">
            <Select
              filterable
              v-model="form1.basicInfo.insureType"
              @onChange="changeGroup('insureType')"
            >
              <Option v-for="item in ybEnum" :value="item.label" :key="item.value">
                {{ item.value }}
              </Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="8 flex">
          <FormItem label="科技人员类型" prop="basicInfo.specialType" :label-width="120">
            <Select filterable v-model="form1.basicInfo.specialType">
              <Option v-for="item in tsEnum" :value="item.label" :key="item.value">
                {{ item.value }}
              </Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="8 flex ai-center">
          <FormItem label="参保地" prop="basicInfo.joinArea" :label-width="100">
            <Input v-model="form1.basicInfo.joinArea"></Input>
          </FormItem>
        </Col>
      </Row>

      <Row style="margin-top: 20px" class="flex space-between ai-center">
        <Col span="8 flex">
          <FormItem label="新生儿入院类型" prop="basicInfo.newBornInType" :label-width="130">
            <Select filterable v-model="form1.basicInfo.newBornInType">
              <Option v-for="item in xhEnum" :value="item.label" :key="item.value">
                {{ item.value }}
              </Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="8 flex ai-center">
          <FormItem label="新生儿出生体重" prop="basicInfo.newBornOutWeight" :label-width="140">
            <Input v-model="form1.basicInfo.newBornOutWeight" @onBlur="changeGroup"></Input>
          </FormItem>
          克</Col
        >

        <Col span="8 flex ai-center">
          <FormItem label="新生儿入院体重" prop="basicInfo.newBornInWeight" :label-width="140">
            <Input v-model="form1.basicInfo.newBornInWeight" @onBlur="changeQc"></Input>
          </FormItem>
          克</Col
        >
      </Row>

      <div class="title1">二、门诊慢特病诊疗信息</div>
      <Row style="margin-top: 20px" class="flex space-between">
        <Col span="12 flex ai-center">
          <FormItem label="诊断科别" prop="basicInfo.val17" :label-width="100">
            <Select filterable clearable v-model="form1.basicInfo.val17">
              <Option v-for="item in classList" :value="item.label" :key="item.value">
                {{ item.value }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="12 flex ai-center">
          <FormItem label="就诊日期" prop="basicInfo.val18" :label-width="100">
            <DatePicker
              v-model="form1.basicInfo.val18"
              type="date"
              format="yyyy-MM-dd"
              @on-change="form1.basicInfo.val18 = $event"
            />
          </FormItem>
        </Col>
      </Row>
      <div style="margin-top: 20px">
        <Table :columns="columns1" :data="form1.specialDiagInfos" border="">
          <template #diseaseName="{ index }">
            <FormItem>
              <Input v-model="form1.specialDiagInfos[index].diseaseName"></Input>
            </FormItem>
          </template>
          <template #diseaseCode="{ index }">
            <FormItem>
              <Input v-model="form1.specialDiagInfos[index].diseaseCode"></Input>
            </FormItem>
          </template>
          <template #operName="{ index }">
            <FormItem>
              <Input v-model="form1.specialDiagInfos[index].operName"></Input>
            </FormItem>
          </template>
          <template #operCode="{ index }">
            <FormItem>
              <Input v-model="form1.specialDiagInfos[index].operCode"></Input>
            </FormItem>
          </template>
        </Table>
      </div>

      <div class="title1">三、住院诊疗信息</div>

      <div class="inhoinfo">
        <Row style="margin-top: 20px; padding: 17px 0" class="flex row-border border-bottom-none">
          <Col span="24 flex ai-center">
            <FormItem label="住院医疗类型" prop="diagInfo.medicalType" :label-width="120">
              <RadioGroup v-model="form1.diagInfo.medicalType">
                <Radio label="1">
                  <span>住院</span>
                </Radio>
                <Radio label="2">
                  <span>日间手术</span>
                </Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row class="flex row-border border-bottom-none" style="padding: 17px 0">
          <Col span="24 flex ai-center">
            <FormItem label="入院途径" prop="diagInfo.way" :label-width="120">
              <RadioGroup v-model="form1.diagInfo.way" @onChange="changeQc">
                <Radio label="1">
                  <span>急诊</span>
                </Radio>
                <Radio label="2">
                  <span>门诊</span>
                </Radio>
                <Radio label="3">
                  <span>其他医疗机构转入</span>
                </Radio>
                <Radio label="4">
                  <span>其他</span>
                </Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row class="flex row-border border-bottom-none" style="padding: 17px 0">
          <Col span="24 flex ai-center">
            <FormItem label="治疗类别" prop="diagInfo.healType" :label-width="120">
              <RadioGroup v-model="form1.diagInfo.healType">
                <Radio label="1">
                  <span>西医</span>
                </Radio>
                <Radio label="2.1">
                  <span>中医</span>
                </Radio>
                <Radio label="2.2">
                  <span>民族医</span>
                </Radio>
                <Radio label="3">
                  <span>中西医</span>
                </Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row
          class="flex space-between row-border border-bottom-none ai-center"
          style="padding: 17px 0"
        >
          <Col span="8 flex ai-center">
            <FormItem label="入院时间" prop="diagInfo.inTime" :label-width="100">
              <DatePicker
                v-model="form1.diagInfo.inTime"
                type="date"
                :format="'yyyy-MM-dd HH:mm:ss'"
                @on-change="form1.diagInfo.inTime = $event"
              ></DatePicker>
            </FormItem>
          </Col>

          <Col span="8 flex ai-center">
            <FormItem label="入院科别" prop="diagInfo.inCategory" :label-width="100">
              <Select filterable v-model="form1.diagInfo.inCategory" @onChange="changeQc">
                <Option v-for="item in classList" :value="item.label" :key="item.value">
                  {{ item.value }}
                </Option>
              </Select>
            </FormItem>
          </Col>

          <Col span="8 flex ai-center">
            <FormItem label="转科科别" prop="diagInfo.turnCategory" :label-width="100">
              <Select filterable v-model="form1.diagInfo.turnCategory" @onChange="changeCateGory">
                <Option v-for="item in classList" :value="item.label" :key="item.value">
                  {{ item.value }}
                </Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row
          class="flex space-between row-border border-bottom-none ai-center"
          style="padding: 17px 0"
        >
          <Col span="8 flex ai-center">
            <FormItem label="出院时间" prop="diagInfo.outTime" :label-width="100">
              <DatePicker
                v-model="form1.diagInfo.outTime"
                type="date"
                :format="'yyyy-MM-dd HH:mm:ss'"
                @on-change="form1.diagInfo.outTime = $event"
              ></DatePicker>
            </FormItem>
          </Col>
          <Col span="8 flex ai-center">
            <FormItem label="出院科别" prop="diagInfo.outCategory" :label-width="100">
              <Select filterable v-model="form1.diagInfo.outCategory" @onChange="changeQc">
                <Option v-for="item in classList" :value="item.label" :key="item.value">
                  {{ item.value }}
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="8 flex ai-center">
            <FormItem label="实际住院" prop="diagInfo.inDays" :label-width="100">
              <Input v-model="form1.diagInfo.inDays" @onBlur="changeGroup"></Input> </FormItem
            >天
          </Col>
        </Row>
        <Row class="flex space-between row-border">
          <Col span="12 flex ai-center">
            <FormItem
              label="门（急）诊诊断（西医诊断）"
              prop="diagInfo.in_WM_Diag"
              :label-width="200"
            >
              <Input v-model="form1.diagInfo.in_WM_Diag" @onBlur="changeQc"></Input>
            </FormItem>
          </Col>

          <Col span="12 flex ai-center">
            <FormItem label="疾病代码" prop="diagInfo.in_WM_Code" :label-width="100">
              <Input v-model="form1.diagInfo.in_WM_Code" @onBlur="changeQc"></Input>
            </FormItem>
          </Col>
        </Row>

        <Row class="flex space-between" style="padding: 12px 0">
          <Col span="12 flex ai-center">
            <FormItem
              label="门（急）诊诊断（中医诊断）"
              prop="diagInfo.in_TCM_Diag"
              :label-width="200"
            >
              <Input v-model="form1.diagInfo.in_TCM_Diag"></Input>
            </FormItem>
          </Col>

          <Col span="12 flex ai-center">
            <FormItem label="疾病代码" prop="diagInfo.in_TCM_Code" :label-width="100">
              <Input v-model="form1.diagInfo.in_TCM_Code"></Input>
            </FormItem>
          </Col>
        </Row>

        <Table :columns="columns33" :data="groupedItems" border>
          <template #redName="{ index }">
            <FormItem :prop="`diagInfo.diagItems[${index * 2}].name`">
              <AutoComplete
                v-model="groupedItems[index][0].name"
                :data="diagnosisNameList"
                clearable
                @on-change="handleDiagnosisChangeOper($event, index, 'name')"
                @on-search="handleDiagnosisSearchOper($event, index, 'name')"
                @on-select="handleDiagnosisSelectOper($event, index, 'name')"
                @on-clear="handleDiagnosisClearOper($event, index, 'name')"
                @on-blur="handleBlur"
                transfer
              ></AutoComplete>
            </FormItem>
          </template>
          <template #redCode="{ index }">
            <span>{{ groupedItems[index][0].code }}</span>
            <!-- <FormItem>
              <AutoComplete
                v-model="groupedItems[index][0].code"
                :data="diagnosisNameList"
                clearable
                @on-change="handleDiagnosisChangeOper($event, index, 'code')"
                @on-search="handleDiagnosisSearchOper($event, index, 'code')"
                @on-select="handleDiagnosisSelectOper($event, index, 'code')"
                @on-clear="handleDiagnosisClearOper($event, index, 'code')"
                transfer
              ></AutoComplete>
            </FormItem> -->
          </template>
          <template #redDesc="{ index }">
            <FormItem>
              <Input v-model="groupedItems[index][0].desc" @on-blur="changeQc"></Input>
            </FormItem>
          </template>
          <template #greenName="{ index }">
            <FormItem>
              <Input v-model="groupedItems[index][1].name"></Input>
            </FormItem>
          </template>
          <template #greenCode="{ index }">
            <FormItem>
              <Input v-model="groupedItems[index][1].code"></Input>
            </FormItem>
          </template>
          <template #greenDesc="{ index }">
            <FormItem>
              <Input v-model="groupedItems[index][1].desc"></Input>
            </FormItem>
          </template>
          <template #action="{ index }">
            <Tooltip content="删除" placement="top" transfer>
              <Button
                v-show="groupedItems.length !== 1"
                @click="reduceIndex(1, index)"
                type="error"
                icon="md-remove"
              ></Button>
            </Tooltip>
            <Tooltip content="增加" placement="top" transfer>
              <Button
                v-if="index == groupedItems.length - 1"
                type="primary"
                icon="md-add"
                @click="addIndex(1, index)"
                style="margin-left: 5px"
              ></Button>
            </Tooltip>
            <Tooltip content="设为主要诊断" placement="top" transfer>
              <Button
                v-if="groupedItems[index][0].type == 2"
                type="info"
                @click="chooseIndex(1, index)"
                class="main_btn"
                style="margin-left: 5px"
                ><img src="../../../../assets/主.png" alt="" class="main_img"
              /></Button>
            </Tooltip>
          </template>
        </Table>

        <Row class="flex" style="padding: 12px 0">
          <Col span="5" class="text-label ivu-text-left">诊断代码计数</Col>
          <Col span="6">
            {{ groupedItems.length }}
          </Col>
        </Row>

        <div v-for="(item, index) in form1.diagInfo.operItems" :key="index" class="opertion_list">
          <div class="table-container">
            <table class="my-table">
              <thead>
                <tr>
                  <th style="width: 16.66%">
                    {{ item.type == 1 ? '主要' : '其他' }}手术及操作名称{{
                      item.type == 1 ? '' : index
                    }}
                  </th>
                  <th style="width: 16.66%">
                    {{ item.type == 1 ? '主要' : '其他' }}手术及操作代码{{
                      item.type == 1 ? '' : index
                    }}
                  </th>
                  <th>麻醉方式</th>
                  <th>术者医生姓名</th>
                  <th>术者医生代码</th>
                  <th>麻醉医生姓名</th>
                  <th>麻醉医生代码</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>
                    <FormItem>
                      <AutoComplete
                        v-model="form1.diagInfo.operItems[index].operName"
                        :data="operNameList"
                        clearable
                        @on-change="handleChangeOper($event, item, index, 'name')"
                        @on-search="handleSearchOper($event, item, index, 'name')"
                        @on-select="handleSelectOper($event, item, index, 'name')"
                        @on-clear="
                          form1.diagInfo.operItems[index].operName = form1.diagInfo.operItems[
                            index
                          ].operCode =
                            ''
                        "
                        @on-blur="handleBlur"
                        transfer
                      ></AutoComplete>
                    </FormItem>
                  </td>
                  <td>
                    <span>{{ form1.diagInfo.operItems[index].operCode }}</span>
                    <!-- <FormItem>
                      <AutoComplete
                        v-model="form1.diagInfo.operItems[index].operCode"
                        :data="operNameList"
                        clearable
                        @on-search="handleSearchOper($event, item, index, 'code')"
                        @on-select="handleSelectOper($event, item, index, 'code')"
                        @on-clear="
                          form1.diagInfo.operItems[index].operName = form1.diagInfo.operItems[
                            index
                          ].operCode =
                            ''
                        "
                        transfer
                      ></AutoComplete>
                    </FormItem> -->
                  </td>
                  <td>
                    <FormItem>
                      <Select
                        v-model="form1.diagInfo.operItems[index].way"
                        @on-change="changeQc"
                        transfer
                        style="width: 150px"
                      >
                        <Option v-for="item in mzfsEnum" :value="item.value" :key="item.value">
                          {{ item.label }}
                        </Option>
                      </Select>
                    </FormItem>
                  </td>
                  <td>
                    <FormItem>
                      <Input v-model="form1.diagInfo.operItems[index].operDocName"></Input>
                    </FormItem>
                  </td>
                  <td>
                    <FormItem>
                      <Input v-model="form1.diagInfo.operItems[index].operDocCode"></Input>
                    </FormItem>
                  </td>
                  <td>
                    <FormItem>
                      <Input
                        v-model="form1.diagInfo.operItems[index].anesDocName"
                        @onBlur="changeQc"
                      ></Input>
                    </FormItem>
                  </td>
                  <td>
                    <FormItem>
                      <Input v-model="form1.diagInfo.operItems[index].anesDocCode"></Input>
                    </FormItem>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>

          <Row class="flex space-between" style="padding: 12px 0">
            <Col span="12 flex ai-center">
              <FormItem label="手术及操作起始时间" prop="operTime" :label-width="150">
                <DatePicker
                  v-model="form1.diagInfo.operItems[index].operTime"
                  type="datetime"
                  format="yyyy-MM-dd HH:mm:ss"
                  @on-change="changeOperTime($event, index, 'operTime')"
                />
              </FormItem>
            </Col>
            <Col span="12 flex ai-center">
              <FormItem label="麻醉起始时间" prop="anesTime" :label-width="150">
                <DatePicker
                  v-model="form1.diagInfo.operItems[index].anesTime"
                  type="datetime"
                  format="yyyy-MM-dd HH:mm:ss"
                  @on-change="changeOperTime($event, index, 'anesTime')"
                />
              </FormItem>
            </Col>
          </Row>
          <div class="action_box">
            <div class="choose_box">
              <Tooltip content="设为主手术" placement="top" transfer>
                <Button
                  type="info"
                  @click="chooseOptionIndex(index)"
                  v-if="form1.diagInfo.operItems[index].type == 0"
                  class="main_btn"
                  style="margin-left: 5px"
                  ><img src="../../../../assets/主.png" alt="" class="main_img"
                /></Button>
              </Tooltip>
            </div>
            <div
              class="other_box1"
              v-if="index == form1.diagInfo.operItems.length - 1"
              style="margin-right: 30px"
              @click="addOptionIndex(index)"
            >
              <Tooltip content="增加" placement="top" transfer>
                <Icon type="md-add" size="22" />
              </Tooltip>
            </div>
            <div
              class="other_box"
              v-if="form1.diagInfo.operItems.length !== 1"
              @click="reduceOptionIndex(index)"
            >
              <Tooltip content="删除" placement="top" transfer>
                <Icon type="md-remove" size="22" />
              </Tooltip>
            </div>
          </div>
        </div>

        <Row style="margin-top: 20px" class="flex row-border border-bottom-none">
          <Col span="8 flex">
            <FormItem label="手术及操作代码计数" prop="diagInfo.val23" :label-width="140">
              <Input v-model="form1.diagInfo.val23"></Input>
            </FormItem>
          </Col>
        </Row>
        <Row class="flex row-border border-bottom-none ai-center">
          <Col span="10 flex ai-center">
            <FormItem label="呼吸机使用时间" prop="diagInfo.useDay" :label-width="150">
              <Input v-model="form1.diagInfo.useDay"></Input> </FormItem
            >天
          </Col>
          <Col span="4 flex ai-center">
            <Input v-model="form1.diagInfo.useHour"></Input><span style="width: 40px">小时</span>
          </Col>
          <Col span="4 flex ai-center">
            <Input v-model="form1.diagInfo.useMinute"></Input><span style="width: 40px">分钟</span>
          </Col>
        </Row>

        <div class="row-border">
          <Row class="ai-center flex">
            <Col span="12" class="flex ai-center">
              <FormItem
                label="颅脑损伤患者昏迷时间： 入院前"
                prop="diagInfo.stunDay1"
                :label-width="250"
              >
                <Input v-model="form1.diagInfo.stunDay1"></Input> </FormItem
              >天
            </Col>
            <Col span="4" class="flex ai-center">
              <Input v-model="form1.diagInfo.stunHour1"></Input
              ><span style="width: 40px">小时</span>
            </Col>
            <Col span="4" class="flex ai-center">
              <Input v-model="form1.diagInfo.stunMinute1"></Input
              ><span style="width: 40px">分钟</span>
            </Col>
          </Row>
          <Row style="margin-top: 20px">
            <Col span="12" class="flex ai-center">
              <FormItem label="入院后" prop="diagInfo.stunDay2" :label-width="250">
                <Input v-model="form1.diagInfo.stunDay2"></Input> </FormItem
              >天
            </Col>
            <Col span="4 " class="flex ai-center">
              <Input v-model="form1.diagInfo.stunHour2"></Input
              ><span style="width: 40px">小时</span>
            </Col>
            <Col span="4 " class="flex ai-center">
              <Input v-model="form1.diagInfo.stunMinute2"></Input
              ><span style="width: 40px">分钟</span>
            </Col>
          </Row>
        </div>

        <div style="margin-top: 20px">
          <Table :columns="columns5" :data="form1.diagInfo.icU_Json" border="">
            <template #type="{ index }">
              <FormItem>
                <Input v-model="form1.diagInfo.icU_Json[index].type"></Input>
              </FormItem>
            </template>
            <template #intime="{ index }">
              <FormItem>
                <DatePicker
                  v-model="form1.diagInfo.icU_Json[index].intime"
                  type="datetime"
                  transfer
                  format="yyyy-MM-dd HH:mm:ss"
                  @on-change="handleDateChange($event, index, 'intime')"
                />
              </FormItem>
            </template>
            <template #outtime="{ index }">
              <FormItem>
                <DatePicker
                  v-model="form1.diagInfo.icU_Json[index].outtime"
                  type="datetime"
                  transfer
                  format="yyyy-MM-dd HH:mm:ss"
                  @on-change="handleDateChange($event, index, 'outtime')"
                />
              </FormItem>
            </template>
          </Table>
        </div>
        <div style="margin-top: 5px">
          <Table :columns="columns6" :data="form1.diagInfo.blood_Json" border="">
            <template #type="{ index }">
              <FormItem>
                <Input v-model="form1.diagInfo.blood_Json[index].type"></Input>
              </FormItem>
            </template>
            <template #amount="{ index }">
              <FormItem>
                <Input v-model="form1.diagInfo.blood_Json[index].amount"></Input>
              </FormItem>
            </template>
            <template #unit="{ index }">
              <FormItem>
                <Input v-model="form1.diagInfo.blood_Json[index].unit"></Input>
              </FormItem>
            </template>
          </Table>
        </div>

        <Row style="margin-top: 20px" class="flex space-between row-border border-bottom-none">
          <Col span="6" class="flex ai-center">
            <FormItem label="特级护理天数" prop="diagInfo.care0" :label-width="120">
              <Input v-model="form1.diagInfo.care0"></Input>
            </FormItem>
          </Col>
          <Col span="6" class="flex ai-center">
            <FormItem label="一级护理天数" prop="diagInfo.care1" :label-width="120">
              <Input v-model="form1.diagInfo.care1"></Input>
            </FormItem>
          </Col>
          <Col span="6" class="flex ai-center">
            <FormItem label="二级护理天数" prop="diagInfo.care2" :label-width="120">
              <Input v-model="form1.diagInfo.care2"></Input>
            </FormItem>
          </Col>
          <Col span="6" class="flex ai-center">
            <FormItem label="三级护理天数" prop="diagInfo.care3" :label-width="120">
              <Input v-model="form1.diagInfo.care3"></Input>
            </FormItem>
          </Col>
        </Row>
        <div class="row-border border-bottom-none">
          <row style="padding-bottom: 8px">
            <Col span="6" class="text-label ivu-text-left"><i class="red">*</i> 离院方式 </Col>
            <FormItem prop="diagInfo.outWay">
              <RadioGroup
                v-model="form1.diagInfo.outWay"
                vertical
                @onChange="changeGroup('outWay')"
              >
                <Radio label="1" style="margin-top: 10px">
                  <span>医嘱离院</span>
                </Radio>
                <Radio label="2" style="margin-top: 10px">
                  <span style="margin-right: 10px">医嘱转院，拟接收机构名称</span>
                  <Input
                    v-if="form1.diagInfo.outWay == 2"
                    v-model="form1.diagInfo.outWay_Dept"
                    @onBlur="changeQc"
                  ></Input>
                </Radio>
                <Radio label="3" style="margin-top: 10px">
                  <span style="margin-right: 10px"
                    >转医嘱转社区卫生服务机构/乡镇卫生院，拟接收机构名称</span
                  >
                  <Input
                    v-if="form1.diagInfo.outWay == 3"
                    v-model="form1.diagInfo.outWay_Dept"
                    @onBlur="changeQc"
                  ></Input>
                </Radio>
                <Radio label="4" style="margin-top: 10px">
                  <span>非医嘱离院</span>
                </Radio>
                <Radio label="5" style="margin-top: 10px">
                  <span>死亡</span>
                </Radio>
                <Radio label="9" style="margin-top: 10px">
                  <span>其他</span>
                </Radio>
              </RadioGroup>
            </FormItem>
          </row>
        </div>

        <Row class="flex row-border border-bottom-none">
          <Col span="12 flex" style="padding-bottom: 17px">
            <FormItem
              label="是否有出院31天内再住院计划"
              prop="diagInfo.outAgainType"
              :label-width="230"
            >
              <RadioGroup v-model="form1.diagInfo.outAgainType" vertical @onChange="changeQc">
                <Radio label="1">
                  <span>无</span>
                </Radio>
                <Radio label="2">
                  <span style="margin-right: 10px">有，目的</span>
                  <Input
                    v-if="form1.diagInfo.outAgainType == 2"
                    v-model="form1.diagInfo.outAgainType_Memo"
                    @onBlur="changeQc"
                  ></Input>
                </Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row>
          <table border="1" cellpadding="5px" cellspacing="0" class="table_border_class">
            <thead>
              <tr>
                <td>
                  <Row class="flex" style="padding-bottom: 10px">
                    <Col span="24 flex">
                      <FormItem label="主诊医师姓名" prop="personInfo.dcName" :label-width="120">
                        <Input v-model="form1.personInfo.dcName"></Input>
                      </FormItem>
                    </Col>
                  </Row>
                </td>
                <td>
                  <Row class="flex" style="padding-bottom: 10px">
                    <Col span="24 flex">
                      <FormItem label="主诊医师代码" prop="personInfo.dcCode" :label-width="120">
                        <Input v-model="form1.personInfo.dcCode"></Input>
                      </FormItem>
                    </Col>
                  </Row>
                </td>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>
                  <Row class="flex">
                    <Col span="24 flex">
                      <FormItem label="责任护士姓名" prop="personInfo.nurseName" :label-width="120">
                        <Input v-model="form1.personInfo.nurseName"></Input>
                      </FormItem>
                    </Col>
                  </Row>
                </td>
                <td>
                  <Row class="flex">
                    <Col span="24 flex">
                      <FormItem label="责任护士代码" prop="personInfo.nurseCode" :label-width="120">
                        <Input v-model="form1.personInfo.nurseCode"></Input>
                      </FormItem>
                    </Col>
                  </Row>
                </td>
              </tr>
            </tbody>
          </table>
        </Row>
      </div>

      <div class="title1" style="color: #ff0660">四、医疗收费信息</div>

      <Row>
        <table border="1" cellpadding="5px" cellspacing="0" class="table_border_class">
          <thead>
            <tr>
              <td style="width: 40%">
                <Row class="flex" style="padding: 5px 0">
                  <Col span="24 flex">
                    <FormItem label="业务流水号" prop="chargeInfo.chargeID" :label-width="120">
                      <Input v-model="form1.chargeInfo.chargeID"></Input>
                    </FormItem>
                  </Col>
                </Row>
                <Row class="flex" style="padding: 5px 0">
                  <Col span="24 flex">
                    <FormItem label="票据代码" prop="chargeInfo.ticketCode" :label-width="120">
                      <Input v-model="form1.chargeInfo.ticketCode"></Input>
                    </FormItem>
                  </Col>
                </Row>
                <Row class="flex" style="padding: 5px 0">
                  <Col span="24 flex">
                    <FormItem label="票据号码" prop="chargeInfo.ticketNo" :label-width="120">
                      <Input v-model="form1.chargeInfo.ticketNo"></Input>
                    </FormItem>
                  </Col>
                </Row>
              </td>
              <td style="width: 60%">
                <Row class="flex ai-center">
                  <Col span="11 flex">
                    <FormItem label="结算期间" prop="chargeInfo.startDate" :label-width="120">
                      <DatePicker
                        v-model="form1.chargeInfo.startDate"
                        type="date"
                        format="yyyy-MM-dd HH:mm:ss"
                        @on-change="form1.chargeInfo.startDate = $event"
                      />
                    </FormItem> </Col
                  >-
                  <Col span="11 flex">
                    <FormItem prop="diagInfo.endDate" :label-width="120">
                      <DatePicker
                        v-model="form1.chargeInfo.endDate"
                        type="date"
                        format="yyyy-MM-dd HH:mm:ss"
                        @on-change="form1.chargeInfo.endDate = $event"
                      />
                    </FormItem>
                  </Col>
                </Row>
              </td>
            </tr>
          </thead>
        </table>
      </Row>
      <div style="margin-top: 5px">
        <Table :columns="columns7" :data="form1.chargeInfo.items" show-summary sum-text="金额合计">
          <template #itemName="{ index }">
            {{ form1.chargeInfo.items[index].itemName }}
            <!-- <FormItem>
              <input disabled v-model="form1.chargeInfo.items[index].itemName"></input>
            </FormItem> -->
          </template>
          <template #amount="{ index }">
            <FormItem>
              <InputNumber
                type="number"
                controls-outside
                :min="0"
                v-model="form1.chargeInfo.items[index].amount"
              ></InputNumber>
            </FormItem>
          </template>
          <template #jia="{ index }">
            <FormItem>
              <InputNumber
                type="number"
                controls-outside
                :min="0"
                v-model="form1.chargeInfo.items[index].jia"
              ></InputNumber>
            </FormItem>
          </template>
          <template #yi="{ index }">
            <FormItem>
              <InputNumber
                type="number"
                controls-outside
                :min="0"
                v-model="form1.chargeInfo.items[index].yi"
              ></InputNumber>
            </FormItem>
          </template>
          <template #self="{ index }">
            <FormItem>
              <InputNumber
                type="number"
                controls-outside
                :min="0"
                v-model="form1.chargeInfo.items[index].self"
              ></InputNumber>
            </FormItem>
          </template>
          <template #others="{ index }">
            <FormItem>
              <InputNumber
                type="number"
                controls-outside
                :min="0"
                v-model="form1.chargeInfo.items[index].others"
              ></InputNumber>
            </FormItem>
          </template>
        </Table>
      </div>

      <Row style="margin-top: 5px" class="dd">
        <Col span="24">
          <table border="1" cellpadding="5px" cellspacing="0" class="table_border_class">
            <thead>
              <tr>
                <td colspan="2">医保统筹基金支付</td>
                <td>
                  <FormItem prop="chargeInfo.ybtcjjzf">
                    <Input v-model="form1.chargeInfo.ybtcjjzf"></Input>
                  </FormItem>
                </td>
                <td rowspan="5">个人负担</td>
                <td rowspan="3">个人自负</td>
                <td rowspan="3">
                  <FormItem prop="chargeInfo.grzF1">
                    <Input v-model="form1.chargeInfo.grzF1"></Input>
                  </FormItem>
                </td>
              </tr>
              <tr>
                <td rowspan="3">补充医疗保险支付</td>
                <td>职工大额补助</td>
                <td>
                  <FormItem prop="chargeInfo.zgdebz">
                    <Input v-model="form1.chargeInfo.zgdebz"></Input>
                  </FormItem>
                </td>
              </tr>
              <tr>
                <td>居民大病保险</td>
                <td>
                  <FormItem prop="chargeInfo.jmdbbx">
                    <Input v-model="form1.chargeInfo.jmdbbx"></Input>
                  </FormItem>
                </td>
              </tr>
              <tr>
                <td>公务员医疗补助</td>
                <td>
                  <FormItem prop="chargeInfo.gwyylbz">
                    <Input v-model="form1.chargeInfo.gwyylbz"></Input>
                  </FormItem>
                </td>
                <td rowspan="2">个人自费</td>
                <td rowspan="2">
                  <FormItem prop="chargeInfo.grzF2">
                    <Input v-model="form1.chargeInfo.grzF2"></Input>
                  </FormItem>
                </td>
              </tr>
              <tr>
                <td colspan="2">医疗救助支付</td>
                <td>
                  <FormItem prop="chargeInfo.yljzzf">
                    <Input v-model="form1.chargeInfo.yljzzf"></Input>
                  </FormItem>
                </td>
              </tr>
              <tr>
                <td rowspan="3">其他支付</td>
                <td>企业补充</td>
                <td>
                  <FormItem prop="chargeInfo.qybc">
                    <Input v-model="form1.chargeInfo.qybc"></Input>
                  </FormItem>
                </td>
                <td rowspan="3">个人支付</td>
                <td rowspan="2">个人账户支付</td>
                <td rowspan="2">
                  <FormItem prop="chargeInfo.grzhzf">
                    <Input v-model="form1.chargeInfo.grzhzf"></Input>
                  </FormItem>
                </td>
              </tr>
              <tr>
                <td>商业保险</td>
                <td>
                  <FormItem prop="chargeInfo.sybx">
                    <Input v-model="form1.chargeInfo.sybx"></Input>
                  </FormItem>
                </td>
              </tr>
              <tr>
                <td></td>
                <td>
                  <!-- <FormItem>
                                    <Input v-model="form.chargeInfo.val22"></Input>
                                </FormItem> -->
                </td>
                <td>个人现金支付</td>
                <td>
                  <FormItem prop="chargeInfo.grxjzf">
                    <Input v-model="form1.chargeInfo.grxjzf"></Input>
                  </FormItem>
                </td>
              </tr>
            </thead>
          </table>
        </Col>
      </Row>

      <Row style="margin-top: 20px" class="flex row-border">
        <Col span="12">
          <FormItem prop="chargeInfo.payType" label="医保支付方式" :label-width="120">
            <RadioGroup v-model="form1.chargeInfo.payType">
              <Radio :label="1">
                <span>按项目</span>
              </Radio>
              <Radio :label="2">
                <span>单病种</span>
              </Radio>
              <Radio :label="3">
                <span>按病种分值</span>
              </Radio>
              <Radio :label="4">
                <span>DIP</span>
              </Radio>
              <Radio :label="5">
                <span>按床日</span>
              </Radio>
              <Radio :label="6">
                <span>按人头</span>
              </Radio>
            </RadioGroup>
          </FormItem>
        </Col>
      </Row>
      <Row class="cc">
        <Col span="24">
          <table border="1" cellpadding="5px" cellspacing="0" class="table_border_class">
            <thead>
              <tr>
                <td>
                  <Row class="flex">
                    <Col span="12 flex">
                      <FormItem
                        label="定点医疗机构填报部门"
                        prop="chargeInfo.section"
                        :label-width="160"
                      >
                        <Input v-model="form1.chargeInfo.section"></Input>
                      </FormItem>
                    </Col>
                    <Col span="12 flex">
                      <FormItem label="医保经办机构" prop="chargeInfo.dept" :label-width="130">
                        <Input v-model="form1.chargeInfo.dept"></Input>
                      </FormItem>
                    </Col>
                  </Row>
                  <Row class="flex">
                    <Col span="12 flex">
                      <FormItem
                        label="定点医疗机构填报人"
                        prop="chargeInfo.fillPerson"
                        :label-width="160"
                      >
                        <Input v-model="form1.chargeInfo.fillPerson"></Input>
                      </FormItem>
                    </Col>
                    <Col span="12 flex">
                      <FormItem
                        label="医保机构经办人"
                        prop="chargeInfo.doPerson"
                        :label-width="120"
                      >
                        <Input v-model="form1.chargeInfo.doPerson"></Input>
                      </FormItem>
                    </Col>
                  </Row>
                </td>
              </tr>
            </thead>
          </table>
        </Col>
      </Row>
    </Form>
  </div>
</template>

<script setup>
import cloneDeep from 'lodash/cloneDeep'

import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
import { computed, reactive } from 'vue'
import {
  gjEnum,
  mzEnum,
  mzfsEnum,
  certTypeEnum,
  zyEnum,
  gxEnum,
  ybEnum,
  tsEnum,
  xhEnum,
  Enum1,
  Enum2,
  Enum3,
  Enum4,
  ksEnum,
} from '../unils/enum.js'
import moment from 'moment'
import http from '@/util/http1'
import { QCparams } from '../unils/params.js'
import { handleChangeGroup, shouldTriggerGroup } from '../unils/public.js'
let { proxy } = getCurrentInstance()

const props = defineProps({
  form: Object,
  listID: String,
  classList: Array,
})

const getPlugValue = (params) => {
  console.log('获取插件数据', params)
  if (params && params.diagnoset_Json.length > 0) {
    diagItems.value = []
    const newItems = []
    params.diagnoset_Json.forEach((item) => {
      const westernDiag = {
        diid: '',
        listID: '',
        type: item.IsMain == 1 ? 1 : 2, // 保持主诊断标识
        way: 1,
        desc: '',
        code: item.medicalInsuranceCode,
        name: item.medicalInsuranceName,
      }
      const tcmDiag = {
        diid: '',
        listID: '',
        type: item.IsMain == 1 ? 1 : 2,
        way: 2,
        name: '',
        code: '',
        desc: '',
      }
      newItems.push(westernDiag, tcmDiag)
    })
    diagItems.value = newItems
  } else {
    diagItems.value = diagItems1.value
  }
  form1.diagInfo.diagItems = diagItems.value

  //手术
  if (params && params.operation_Json.length > 0) {
    // form1.diagInfo.operItems = []
    const newOperItems = []
    params.operation_Json.forEach((item) => {
      const newParams = {
        operTime: '', //手术起始时间
        anesTime: '', //麻醉起始时间
        type: item.IsMain, //是否主手
        operName: item.medicalInsuranceName,
        operCode: item.medicalInsuranceCode,
        way: '',
        operDocName: '',
        operDocCode: '',
        anesDocName: '',
        anesDocCode: '',
      }
      newOperItems.push(newParams)
    })
    form1.diagInfo.operItems = newOperItems
  } else {
    form1.diagInfo.operItems = operItems.value
  }
}

const setEditGroupInfo = (params) => {
  form1.extra.group_Name = params.name || ''
  form1.extra.group_Code = params.code || ''
}

let form1 = reactive({
  head: {},
  basicInfo: {},
  diagInfo: {
    icU_Json: [],
    blood_Json: [],
    diagItems: [],
  },
  personInfo: {},
  chargeInfo: {
    items: [],
  },
  extra: {},
  qcInfos: [],
})

const validateDiagName = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('请选择主要诊断'))
  }
}

const ruleValidate = {
  'head.hospitalName': [{ required: true, message: '请输入定点医疗机构名称', trigger: 'blur' }],
  'head.hospitalCode': [{ required: true, message: '请输入定点医疗机构代码', trigger: 'blur' }],
  'head.level': [{ required: true, message: '请输入医保结算等级', trigger: 'blur' }],
  'head.number': [{ required: true, message: '请输入病案号', trigger: 'blur' }],
  'basicInfo.realName': [{ required: true, message: '请输入姓名', trigger: 'blur' }],
  'basicInfo.sex': [{ required: true, message: '请选择性别', trigger: 'blur' }],
  'basicInfo.coutry': [{ required: true, message: '请选择国籍', trigger: 'blur' }],
  'basicInfo.nation': [{ required: true, message: '请选择民族', trigger: 'blur' }],
  'basicInfo.certType': [{ required: true, message: '请选择患者证件类别', trigger: 'blur' }],
  'basicInfo.certNo': [{ required: true, message: '请输入患者证件号码', trigger: 'blur' }],
  'basicInfo.jobType': [{ required: true, message: '请选择职业', trigger: 'blur' }],
  'basicInfo.homeAddress': [{ required: true, message: '请输入现住址', trigger: 'blur' }],
  'basicInfo.insureType': [
    { required: true, type: 'number', message: '请选择医保类型', trigger: 'blur' },
  ],
  'diagInfo.medicalType': [{ required: true, message: '请选择住院医疗类型', trigger: 'blur' }],
  'diagInfo.way': [{ required: true, message: '请选择入院途径', trigger: 'blur' }],
  'diagInfo.inTime': [{ required: true, message: '请选择入院时间', trigger: 'blur' }],
  'diagInfo.inCategory': [{ required: true, message: '请选择入院科别', trigger: 'blur' }],
  'diagInfo.outTime': [{ required: true, message: '请选择出院时间', trigger: 'blur' }],
  'diagInfo.outCategory': [{ required: true, message: '请选择出院科别', trigger: 'blur' }],
  'diagInfo.inDays': [
    {
      required: true,
      validator: (rule, value, callback) => {
        if (value === '' || value === null || value === undefined) {
          callback(new Error('请输入实际住院'))
        } else {
          callback()
        }
      },
      trigger: 'blur',
    },
  ],
  'diagInfo.outWay': [{ required: true, message: '请选择离院方式', trigger: 'blur' }],
  'diagInfo.outAgainType': [{ required: true, message: '请选择', trigger: 'blur' }],
  'personInfo.dcName': [{ required: true, message: '请输入主诊医师姓名', trigger: 'blur' }],
  'personInfo.dcCode': [{ required: true, message: '请输入主诊医师代码', trigger: 'blur' }],
  'diagInfo.diagItems[0].name': [
    {
      required: true,
      trigger: ['blur', 'change'],
      validator: validateDiagName,
    },
  ],
}

const debounce = (fn, delay) => {
  let timer = null
  return function (...args) {
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
      fn.apply(this, args)
    }, delay)
  }
}

const diagnosisNameList = ref([])

const amountTotal = computed(() => {
  const items = form1.chargeInfo.items
  let total = 0

  if (items?.length > 0) {
    total = items.reduce((sum, item) => {
      return (
        sum +
        Number(item.amount || 0) +
        Number(item.jia || 0) +
        Number(item.yi || 0) +
        Number(item.self || 0) +
        Number(item.others || 0)
      )
    }, 0)
  }

  return total
})

// 分组器
const changeGroup = (type = '', isNotQc = false) => {
  if (!shouldTriggerGroup(type, form1.basicInfo[type] || form1.diagInfo[type])) {
    changeQc()
    return
  }
  const groupData = {
    diagItems: diagItems.value,
    basicInfo: form1.basicInfo,
    diagInfo: form1.diagInfo,
    chargeInfo: form1.chargeInfo,
    amountTotal: amountTotal.value,
  }
  const params = handleChangeGroup(groupData)
  emits('changeGroupInfo', params)
  if (!isNotQc) {
    changeQc()
  }
}

const Qclist = ref([])

const changeQc = async (qcName = '', formFrom = '', formName = '') => {
  QCparams.username = form1.head.hospitalName
  QCparams.ylfkfs = form1.head.insureType
  QCparams.jkkh = form1.head.certNo
  QCparams.bah = form1.head.number
  QCparams.zycs = form1.diagInfo.inCount
  QCparams.xm = form1.basicInfo.realName
  QCparams.xb = form1.basicInfo.sex
  QCparams.csrq = `${form1.basicInfo.year}${form1.basicInfo.month}${form1.basicInfo.day}`
  QCparams.nl = form1.basicInfo.age
  QCparams.gj = form1.basicInfo.coutry
  QCparams.xsecstz = form1.basicInfo.newBornOutWeight
  QCparams.xserytz = form1.basicInfo.newBornInWeight
  QCparams.csd = form1.basicInfo.bornAddr
  QCparams.gg = form1.basicInfo.origin
  QCparams.mz = form1.basicInfo.nation
  QCparams.sfzh = form1.basicInfo.certNo
  QCparams.zy = form1.basicInfo.jobType
  QCparams.hy = form1.basicInfo.marriage
  QCparams.xzz = form1.basicInfo.homeAddress
  QCparams.dh = form1.basicInfo.dh
  QCparams.yB1 = form1.basicInfo.homePostCode
  QCparams.hkdz = form1.basicInfo.postCode
  QCparams.yB2 = form1.basicInfo.yb2
  QCparams.gzdwjdz = form1.basicInfo.jobAddress
  QCparams.dwdh = form1.basicInfo.jobPhone
  QCparams.yb3 = form1.basicInfo.jobPostCode
  QCparams.lxrxm = form1.basicInfo.contactName
  QCparams.gx = form1.basicInfo.contactType
  QCparams.dz = form1.basicInfo.contactAddress
  QCparams.dh2 = form1.basicInfo.contactPhone
  QCparams.rytj = form1.diagInfo.way
  QCparams.rysj = form1.diagInfo.inTime
    ? moment(form1.diagInfo.inTime, 'YYYY-MM-DD HH:mm:ss').format('YYYYMMDD')
    : ''
  QCparams.rysjs = form1.diagInfo.inTime
    ? moment(form1.diagInfo.inTime, 'YYYY-MM-DD HH:mm:ss').format('HH')
    : ''
  QCparams.rykb = form1.diagInfo.inDCategory
  QCparams.rybf = form1.diagInfo.inRoom
  QCparams.zkkb = form1.diagInfo.turnCategory
  QCparams.cysj = form1.diagInfo.outTime
    ? moment(form1.diagInfo.outTime, 'YYYY-MM-DD HH:mm:ss').format('YYYYMMDD')
    : ''
  QCparams.cysjs = form1.diagInfo.outTime
    ? moment(form1.diagInfo.outTime, 'YYYY-MM-DD HH:mm:ss').format('HH')
    : ''
  QCparams.cykb = form1.diagInfo.outCategory
  QCparams.cybf = form1.diagInfo.outRoom
  QCparams.sjzyts = form1.diagInfo.inDays
  QCparams.mzzd = form1.diagInfo.in_WM_Diag
  QCparams.jbdm = form1.diagInfo.in_WM_Code
  QCparams.wbyy = form1.diagInfo.poison
  QCparams.h23 = form1.diagInfo.poisonCode
  QCparams.blzd = form1.diagInfo.pathology
  QCparams.jbmm = form1.diagInfo.pathologyCode
  QCparams.blh = form1.diagInfo.pathologyNo
  QCparams.ywgm = form1.diagInfo.react
  QCparams.gmyw = form1.diagInfo.reactName
  QCparams.swhzsj = form1.diagInfo.deathCheck
  QCparams.xx = form1.diagInfo.bloodType
  QCparams.rh = form1.diagInfo.rh

  //主诊列表
  QCparams.zyzd = diagItems.value[0]?.name || ''
  QCparams.jbdm = diagItems.value[0]?.code || ''
  QCparams.rybq = diagItems.value[0]?.desc || ''
  for (let i = 1; i <= 15; i++) {
    const index = i * 2
    const item = diagItems.value[index] || {}
    QCparams[`qtzD${i}`] = item.name || ''
    QCparams[`jbdM${i}`] = item.code || ''
    QCparams[`rybQ${i}`] = item.desc || ''
  }
  //主手列表
  for (let i = 0; i <= 7; i++) {
    const index = i - 1
    const item = form1.diagInfo.operItems[index] || {}
    QCparams[`ssjczmC${i}`] = item.operName || ''
    QCparams[`ssjczbM${i}`] = item.operCode || ''
    QCparams[`ssjczrQ${i}`] = item.operTime
      ? moment(form1.diagInfo.operItems[index].operTime, 'YYYY-MM-DD HH:mm:ss').format('YYYYMMDD')
      : ''
    QCparams[`ssjB${i}`] = item.level || ''
    QCparams[`sZ${i}`] = item.sz || ''
    QCparams[`yZ${i}`] = item.yz || ''
    QCparams[`eZ${i}`] = item.ez || ''
    QCparams[`qkdJ${i}`] = item.cutLevel || ''
    QCparams[`qkyhlB${i}`] = item.cutType || ''
    QCparams[`mzfS${i}`] = item.way || ''
    QCparams[`mzyS${i}`] = item.anesDocName || ''
  }
  QCparams.kzr = form1.personInfo.kzr
  QCparams.zrys = form1.personInfo.zrys
  QCparams.zzys = form1.personInfo.dcName
  QCparams.zyys = form1.personInfo.zyys
  QCparams.zrhs = form1.personInfo.nurseName
  QCparams.jxys = form1.personInfo.jxys
  QCparams.sxys = form1.personInfo.sxys
  QCparams.bmy = form1.personInfo.bmy
  QCparams.bazl = form1.diagInfo.bazl
  QCparams.zkys = form1.personInfo.zkys
  QCparams.zkhs = form1.personInfo.zkhs
  QCparams.zkrq = form1.diagInfo.zkrq
    ? moment(form1.diagInfo.zkrq, 'YYYY-MM-DD HH:mm:ss').format('YYYYMMDD')
    : ''
  QCparams.lyfs = form1.diagInfo.outWay
  QCparams.yzzY_JGMC = form1.diagInfo.outWay_Dept
  QCparams.wsY_JGMC = form1.diagInfo.outWay_Dept
  QCparams.zzyjh = form1.diagInfo.outAgainType
  QCparams.md = form1.diagInfo.outAgainType_Memo
  QCparams.ryQ_T = form1.diagInfo.ryQ_T
  QCparams.ryQ_XS = form1.diagInfo.ryQ_XS
  QCparams.ryQ_FZ = form1.diagInfo.ryQ_FZ
  QCparams.ryH_T = form1.diagInfo.ryH_T
  QCparams.ryH_XS = form1.diagInfo.ryH_XS
  QCparams.ryH_FZ = form1.diagInfo.ryH_FZ
  QCparams.zfy = form1.diagInfo.total
  QCparams.zfje = form1.diagInfo.zfje
  QCparams.ylfuf = form1.diagInfo.ybylfwf
  QCparams.zlczf = form1.diagInfo.ybzlczf
  QCparams.hlf = form1.diagInfo.hlf
  QCparams.qtfy = form1.diagInfo.qtfy
  QCparams.blzdf = form1.diagInfo.blzdf
  QCparams.syszdf = form1.diagInfo.syszdf
  QCparams.yxxzdf = form1.diagInfo.yxxzdf
  QCparams.lczdxmf = form1.diagInfo.lczdxmf
  QCparams.fsszlxmf = form1.diagInfo.fsszlxmf
  QCparams.wlzlf = form1.diagInfo.lcwlzlf
  QCparams.sszlf = form1.diagInfo.sszlf
  QCparams.maf = form1.diagInfo.mzf
  QCparams.ssf = form1.diagInfo.ssf
  QCparams.kff = form1.diagInfo.kff
  QCparams.zyzlf = form1.diagInfo.zyzlf
  QCparams.xyf = form1.diagInfo.xyf
  QCparams.kjywf = form1.diagInfo.kjywf
  QCparams.zcyf = form1.diagInfo.zcyf
  QCparams.zcyf1 = form1.diagInfo.zcyf1
  QCparams.xf = form1.diagInfo.xf
  QCparams.bdblzpf = form1.diagInfo.bdblzpf
  QCparams.qdblzpf = form1.diagInfo.qdblzpf
  QCparams.nxyzlzpf = form1.diagInfo.nxyzlzpf
  QCparams.xbyzlzpf = form1.basicInfo.xbyzlzpf
  QCparams.hcyyclf = form1.basicInfo.jcclf
  QCparams.yyclf = form1.basicInfo.zlclf
  QCparams.ycxyyclf = form1.basicInfo.ssclf
  QCparams.qtf = form1.basicInfo.qtf

  const res = await http.post('/QC/Err/FromPlugin', QCparams)
  Qclist.value = res.data || []

  emits('changeQcInfo', res.data)
}

const emitChangeDiagItems = debounce((code) => {
  emits('changeDiagItems', code)
}, 500)

const handleBlur = () => {
  debounce(() => {
    changeGroup()
  }, 300)()
}

const handleDiagnosisChangeOper = async (value, index, type) => {
  if (!value) {
    groupedItems.value[index][0].code = groupedItems.value[index][0].name = ''
    if (groupedItems.value[index][0].type == 1) {
      emits('changeDiagItems', groupedItems.value[index][0].code)
    }
  } else {
    if (groupedItems.value[index][0].type == 1) {
      emitChangeDiagItems(groupedItems.value[index][0].code)
    }
    diagnosisNameList.value = []
  }
}

//主诊模糊查询
const handleDiagnosisSearchOper = async (value, index, type) => {
  const res = await http.get('/Basic/PolicyEnum/TopLikeDiag', { input: value })
  diagnosisNameList.value = res.data.map((item) => `${item.code}  ${item.name}`)
}

const handleDiagnosisSelectOper = (value, index, type) => {
  if (value) {
    let arr = value.split('  ')
    groupedItems.value[index][0].code = arr[0]
    groupedItems.value[index][0].name = arr[1]
    if (groupedItems.value[index][0].type == 1) {
      emits('changeDiagItems', groupedItems.value[index][0].code)
    }
  } else {
    groupedItems.value[index][0].code = groupedItems.value[index][0].name = ''
  }
}

const handleDiagnosisClearOper = (value, index, type) => {
  groupedItems.value[index][0].code = groupedItems.value[index][0].name = ''
}

const operNameList = ref([])

const emitChangeOperItems = debounce((code) => {
  emits('selectOption', code)
}, 500)

//主手change
const handleChangeOper = (value, items, index, type) => {
  if (!value) {
    form1.diagInfo.operItems[index].operName = form1.diagInfo.operItems[index].operCode = ''
    if (form1.diagInfo.operItems[index].type == 1) {
      emits('selectOption', form1.diagInfo.operItems[index].operCode)
    }
  } else {
    if (form1.diagInfo.operItems[index].type == 1) {
      emitChangeOperItems(form1.diagInfo.operItems[index].operCode)
    }
    operNameList.value = []
  }
}
//主手模糊查询
const handleSearchOper = async (value, items, index, type) => {
  const res = await http.get('/Basic/PolicyEnum/TopLike', { input: value })
  operNameList.value = res.data.map((item) => `${item.code}  ${item.name}`)
}

const handleSelectOper = (value, items, index, type) => {
  if (value) {
    let arr = value.split('  ')
    form1.diagInfo.operItems[index].operCode = arr[0]
    form1.diagInfo.operItems[index].operName = arr[1]
    if (form1.diagInfo.operItems[index].type == 1) {
      emits('selectOption', form1.diagInfo.operItems[index].operCode)
    }
  } else {
    form1.diagInfo.operItems[index].operCode = form1.diagInfo.operItems[index].operName = ''
  }
}

const changeOperTime = (value, index, type) => {
  form1.diagInfo.operItems[index][type] = $event
  changeQc()
}

const changeBirthday = (value) => {
  form1.basicInfo.csrq = value
  form1.basicInfo.year = value.split('-')[0] || ''
  form1.basicInfo.month = value.split('-')[1] || ''
  form1.basicInfo.day = value.split('-')[2] || ''
  changeQc()
}

const formRef = ref(null)
const sub = () => {
  return new Promise((resolve, reject) => {
    formRef.value.validate((valid) => {
      if (valid) {
        try {
          if (!groupedItems.value[0][0].name || !groupedItems.value[0][0].code) {
            reject('请完善主诊断信息')
            return
          }
          http
            .get('/Basic/PolicyEnum/TopLikeDiag', { input: groupedItems.value[0][0].name })
            .then((response) => {
              if (response.data.length === 0) {
                reject('没有该诊断请重新选择')
                return
              }

              const params = cloneDeep(form1)
              params.head.listID = props.listID
              params.basicInfo.listID = props.listID
              params.diagInfo.operItems.forEach((item) => {
                item.listID = props.listID
                item.doid = item.doid || ''
                if (!item.operTime) {
                  item.operTime = '2025-04-03 12:22:24'
                }
                if (!item.anesTime) {
                  item.anesTime = '2025-04-03 12:22:24'
                }
                if (item.type == 1) {
                  params.extra.oper_Name = item.operName
                  params.extra.oper_Code = item.operCode
                }
              })
              params.diagInfo.diagItems = diagItems.value
              params.diagInfo.diagItems.forEach((item) => {
                item.diid = item.diid ? item.diid : ''
                item.listID = item.listID ? item.listID : props.listID
              })

              params.chargeInfo.items.forEach((item) => {
                item.ciid = ciid.value
              })

              params.diagInfo.blood_Json = JSON.stringify(params.diagInfo.blood_Json)
              params.diagInfo.icU_Json = JSON.stringify(params.diagInfo.icU_Json)
              Qclist.value.forEach((item) => {
                item.qiid = item.qiid ? item.qiid : ''
                item.listID = item.listID ? item.listID : props.listID
              })
              params.qcInfos = Qclist.value
              params.extra.categoryID = params.diagInfo.outCategory
              params.extra.categoryName = props.classList.find(
                (item) => item.label == params.diagInfo.outCategory,
              ).value
              params.specialDiagInfos.forEach((item) => {
                item.sdid = item.sdid ? item.sdid : ''
                item.listID = item.listID ? item.listID : props.listID
              })
              console.log(params)
              http.post('/Settlement/List/AddOrUpdate', toRaw(params)).then((response) => {
                if (response.flag) {
                  proxy.$Message.success(response.msg)
                  resolve()
                  setTimeout(() => {
                    router.push({ path: '/Settlement/newList/PageList' })
                  }, 1000)
                } else {
                  reject(response.msg)
                }
              })
            })
        } catch (error) {
          reject(error)
        }
      } else {
        let firstError = ''
        Object.keys(formRef.value.fields).forEach((key) => {
          const field = formRef.value.fields[key]
          if (field.validateState === 'error' && !firstError) {
            firstError = field.validateMessage
          }
        })

        if (firstError) {
          reject(firstError)
        } else {
          proxy.$Message.error('表单验证失败，请检查必填项')
        }
      }
    })
  })
}

const columns33 = [
  {
    title: '出院西医诊断',
    slot: 'redName',
    align: 'center',
    renderHeader: (h) =>
      h('span', [
        h('span', { style: { color: 'red', 'margin-right': '2px' } }, '*'),
        h('span', '出院西医诊断'),
      ]),
  },
  {
    title: '病种代码',
    slot: 'redCode',
    align: 'center',
    renderHeader: (h) =>
      h('span', [
        h('span', { style: { color: 'red', 'margin-right': '2px' } }, '*'),
        h('span', '病种代码'),
      ]),
  },
  { title: '入院病情', align: 'center', slot: 'redDesc' },
  { title: '出院中医诊断', align: 'center', slot: 'greenName' },
  { title: '病种代码', align: 'center', slot: 'greenCode' },
  { title: '入院病情', align: 'center', slot: 'greenDesc' },
  { title: '操作', slot: 'action', align: 'center', width: 160 },
]
const diagItems = ref([])
const diagItems1 = ref([
  {
    diid: '',
    listID: '',
    type: 1,
    way: 1,
    name: '',
    code: '',
    desc: '',
  },
  {
    diid: '',
    listID: '',
    type: 1,
    way: 2,
    name: '',
    code: '',
    desc: '',
  },
])
diagItems.value =
  props.form.diagInfo.diagItems.length > 0 ? props.form.diagInfo.diagItems : diagItems1.value

const groupedItems = computed(() => {
  const result = []
  const items = diagItems.value || []

  for (let i = 0; i < items.length; i += 2) {
    const defaultSecondItem = {
      diid: '',
      listID: '',
      type: items[i]?.type || 2,
      way: 2,
      name: '',
      code: '',
      desc: '',
    }

    result.push([items[i], items[i + 1] || defaultSecondItem])
  }

  if (result.length === 0) {
    result.push([
      {
        diid: '',
        listID: '',
        type: 1,
        way: 1,
        name: '',
        code: '',
        desc: '',
      },
      {
        diid: '',
        listID: '',
        type: 1,
        way: 2,
        name: '',
        code: '',
        desc: '',
      },
    ])
  }
  return result
})

//转换日期格式
const handleDateChange = (val, index, valName) => {
  form1.diagInfo.icU_Json[index][valName] = moment(val).format('YYYY-MM-DD HH:mm:ss')
  if (form1.diagInfo.icU_Json[index].intime && form1.diagInfo.icU_Json[index].outtime) {
    const entryTime = moment(form1.diagInfo.icU_Json[index].intime)
    const exitTime = moment(form1.diagInfo.icU_Json[index].outtime)
    if (exitTime.isBefore(entryTime)) {
      form1.diagInfo.icU_Json[index].outtime = ''
      proxy.$Message.error('出院时间不能早于入院时间')
      return
    }
    const duration = moment.duration(exitTime.diff(entryTime))
    const formattedDuration = `${Math.floor(duration.asHours()) || '0'}小时 ${duration.minutes() || '0'}分钟`

    form1.diagInfo.icU_Json[index].total = formattedDuration
  }
  changeQc()
}
const emits = defineEmits(['changeDiagItems', 'selectOption', 'changeQcInfo', 'changeGroupInfo'])

defineExpose({
  form1,
  getPlugValue,
  setEditGroupInfo,
  sub,
})

const columns1 = [
  {
    title: '病种名称',
    align: 'center',
    key: 'diseaseName',
    slot: 'diseaseName',
  },
  {
    title: '病种代码',
    align: 'center',
    key: 'diseaseCode',
    slot: 'diseaseCode',
  },
  {
    title: '手术及操作名称',
    align: 'center',
    key: 'operName',
    slot: 'operName',
  },
  {
    title: '手术及操作代码',
    align: 'center',
    key: 'operCode',
    slot: 'operCode',
  },
]

const specialDiagInfos = ref([
  {
    diseaseName: '',
    diseaseCode: '',
    operName: '',
    operCode: '',
  },
  {
    diseaseName: '',
    diseaseCode: '',
    operName: '',
    operCode: '',
  },
  {
    diseaseName: '',
    diseaseCode: '',
    operName: '',
    operCode: '',
  },
])

let dataList2 = reactive([
  {
    type: 1, //判断是否是主诊和主手
    diseaseName: '', //出院西医诊断
    diseaseCode: '', //西医病种代码
    operName: '', //西医入院病情
    diseaseName1: '', //出院中医诊断
    diseaseCode1: '', //中医疾病代码
    operName1: '', //中医入院病情
    listindex: 0,
  },
])

// 主诊减
const reduceIndex = (type, index) => {
  if (groupedItems.value[index][0].type == 1) {
    proxy.$Message.error('主诊不能删除,请先选择其他主诊')
    return
  }
  diagItems.value.splice(2, 2)
  handleBlur()
}

// 主诊新增
const addIndex = (num) => {
  diagItems.value.push(
    { diid: '', listID: '', type: 2, way: 1, name: '', code: '', desc: '' },
    { diid: '', listID: '', type: 2, way: 2, name: '', code: '', desc: '' },
  )
}

//选择主诊
const chooseIndex = (type, index) => {
  diagItems.value.forEach((item, i) => {
    if (Math.floor(i / 2) === index) {
      item.type = 1
    } else {
      item.type = 2
    }
  })

  if (index !== 0) {
    const selectedItems = diagItems.value.splice(index * 2, 2)
    diagItems.value.unshift(...selectedItems)
  }
  handleBlur()
}

const columns5 = [
  {
    title: '重症监护病房类型（CUU、NICU、ECU、SICU、PICU、RICU、ICU(综合)、其他） ',
    align: 'center',
    key: 'type',
    renderHeader: (h) =>
      h('div', [
        h('div', '重症监护病房类型'),
        h('div', '（CUU、NICU、ECU、SICU、'),
        h('div', 'PICU、RICU、ICU(综合)、其他）'),
      ]),
    slot: 'type',
  },
  {
    title: '进重症监护室时间',
    align: 'center',
    renderHeader: (h) => h('div', [h('div', '进重症监护室时间'), h('div', '（_年_月_日_时_分）')]),
    slot: 'intime',
  },
  {
    title: '出重症监护室时间',
    align: 'center',
    slot: 'outtime',
    renderHeader: (h) => h('div', [h('div', '出重症监护室时间'), h('div', '（_年_月_日_时_分）')]),
  },
  {
    title: '合计（_时_分）',
    align: 'center',
    key: 'total',
  },
]
const data5 = ref([
  { type: '', intime: '', outtime: '', total: '' },
  { type: '', intime: '', outtime: '', total: '' },
  { type: '', intime: '', outtime: '', total: '' },
])
const columns6 = [
  {
    title: '输血品种',
    align: 'center',
    slot: 'type',
  },
  {
    title: '输血量',
    align: 'center',
    slot: 'amount',
  },
  {
    title: '输血计量单位',
    align: 'center',
    slot: 'unit',
  },
]
const data6 = ref([
  { type: '', amount: '', unit: '' },
  { type: '', amount: '', unit: '' },
  { type: '', amount: '', unit: '' },
])
const columns7 = [
  {
    title: '项目名称',
    align: 'center',
    slot: 'itemName',
  },
  {
    title: '金额',
    align: 'center',
    slot: 'amount',
  },
  {
    title: '甲类',
    align: 'center',
    slot: 'jia',
  },
  {
    title: '乙类',
    align: 'center',
    slot: 'yi',
  },
  {
    title: '自费',
    align: 'center',
    slot: 'self',
  },
  {
    title: '其他',
    align: 'center',
    slot: 'others',
  },
]

const data7 = ref([
  { itemName: '床位费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '诊察费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '检查费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '化验费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '治疗费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '手术费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '护理费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '卫生材料费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '西药费', amount: '', val3: '', yi: '', self: '', others: '' },
  { itemName: '中药饮片费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '中成药费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '一般诊疗费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '挂号费', amount: '', jia: '', yi: '', self: '', others: '' },
  { itemName: '其他费', amount: '', jia: '', yi: '', self: '', others: '' },
])

const operItems = ref([
  {
    operTime: '', //手术起始时间
    anesTime: '', //麻醉起始时间
    type: 1, //是否主手
    operName: '',
    operCode: '',
    way: '',
    operDocName: '',
    operDocCode: '',
    anesDocName: '',
    anesDocCode: '',
  },
])

// 主手诊减
const reduceOptionIndex = (index) => {
  if (form1.diagInfo.operItems[index].type == 1) {
    proxy.$Message.error('主手不能删除,请先选择其他主手')
    return
  }
  form1.diagInfo.operItems.splice(index, 1)
  handleBlur()
}

// 主手新增
const addOptionIndex = (index) => {
  form1.diagInfo.operItems.push({
    operTime: '', //手术起始时间
    anesTime: '', //麻醉起始时间
    type: 0, //是否主手
    operName: '',
    operCode: '',
    way: '',
    operDocName: '',
    operDocCode: '',
    anesDocName: '',
    anesDocCode: '',
  })
}

// 选择主手
const chooseOptionIndex = (index) => {
  form1.diagInfo.operItems.forEach((item, i) => {
    if (i === index) {
      item.type = 1
    } else {
      item.type = 0
    }
  })

  let selectObject = form1.diagInfo.operItems[index]
  form1.diagInfo.operItems = [
    selectObject,
    ...form1.diagInfo.operItems.filter((_, i) => i !== index),
  ]
  handleBlur()
}

form1.head = props.form.head
form1.head.level = props.form.head.level
form1.head.declareTime = moment().format('YYYY-MM-DD HH:mm:ss')

form1.basicInfo = props.form.basicInfo
form1.basicInfo.realName = props.form.basicInfo.realName
form1.basicInfo.sex = props.form.basicInfo.sex.toString()
form1.basicInfo.csrq = `${props.form.basicInfo.year}-${props.form.basicInfo.month}-${props.form.basicInfo.day}`
form1.basicInfo.coutry = props.form.basicInfo.coutry
form1.basicInfo.nation = props.form.basicInfo.nation
form1.basicInfo.certType = props.form.basicInfo.certType
form1.basicInfo.certNo = props.form.basicInfo.certNo
form1.basicInfo.jobType = props.form.basicInfo.jobType
form1.basicInfo.homeAddress = props.form.basicInfo.homeAddress
form1.basicInfo.insureType = props.form.basicInfo.insureType
  ? Number(props.form.basicInfo.insureType)
  : 1

form1.diagInfo = props.form.diagInfo
form1.diagInfo.medicalType = props.form.diagInfo.medicalType.toString()
form1.diagInfo.way = props.form.diagInfo.way ? props.form.diagInfo.way.toString() : ''
form1.diagInfo.healType = props.form.diagInfo.healType ? Number(props.form.diagInfo.healType) : ''
form1.diagInfo.inTime = moment(props.form.diagInfo.inTime).format('YYYY-MM-DD HH:mm:ss')
form1.diagInfo.inCategory = props.form.diagInfo.inCategory
form1.diagInfo.outTime = moment(props.form.diagInfo.outTime).format('YYYY-MM-DD HH:mm:ss')
form1.diagInfo.outCategory = props.form.diagInfo.outCategory
form1.diagInfo.outWay = props.form.diagInfo.outWay ? props.form.diagInfo.outWay.toString() : ''
form1.diagInfo.outAgainType = props.form.diagInfo.outAgainType
  ? props.form.diagInfo.outAgainType.toString()
  : ''

form1.personInfo = props.form.personInfo
form1.personInfo.dcName = props.form.personInfo.dcName
form1.personInfo.dcCode = props.form.personInfo.dcCode

form1.extra = props.form.extra

form1.chargeInfo = props.form.chargeInfo

form1.chargeInfo.payType = props.form.chargeInfo.payType
  ? Number(props.form.chargeInfo.payType)
  : ''

if (!props.form.diagInfo.diagItems || props.form.diagInfo.diagItems.length == 0) {
  form1.diagInfo.diagItems = diagItems.value
} else {
  form1.diagInfo.diagItems = props.form.diagInfo.diagItems
}
form1.diagInfo.operItems =
  props.form.diagInfo.operItems.length > 0 ? ref(props.form.diagInfo.operItems) : operItems.value

if (props.form.chargeInfo.items.length == 0) {
  form1.chargeInfo.items = data7.value
} else {
  form1.chargeInfo.items = props.form.chargeInfo.items
}

if (props.form.diagInfo.icU_Json.length == 0) {
  form1.diagInfo.icU_Json = data5.value
} else {
  form1.diagInfo.icU_Json = props.form.diagInfo.icU_Json
}

if (props.form.diagInfo.blood_Json.length == 0) {
  form1.diagInfo.blood_Json = data6.value
} else {
  form1.diagInfo.blood_Json = props.form.diagInfo.blood_Json
}

form1.qcInfos = props.form.qcInfos
// if (props.form.specialDiagInfos.length == 0) {
//   form1.specialDiagInfos = specialDiagInfos.value
// } else {
form1.specialDiagInfos = props.form.specialDiagInfos
// }

const diid = ref('')
const doid = ref('')
const ciid = ref('')
const sdid = ref('')
// diid.value = props.form.diagInfo.diagItems[0]?.diid || ''
// doid.value = props.form.diagInfo.operItems[0].doid || ''
// ciid.value = props.form.chargeInfo.items[0]?.ciid || ''
// sdid.value = props.form.specialDiagInfos[0].sdid
// form1.diagInfo.diagItems = dataList2
</script>

<style lang="less" scoped>
/deep/.ivu-select-single .ivu-select-selection .ivu-select-placeholder,
/deep/.ivu-select-single .ivu-select-selection .ivu-select-selected-value {
  text-align: left;
}
/deep/.autocomplete-dropdown {
  position: absolute;
  z-index: 9999;
}
/deep/ .ivu-form-item {
  margin-bottom: 0;
  flex: 1;
}

/deep/ .ivu-table .ivu-form-item-content {
  margin-left: 0 !important;
}

.jc-center {
  justify-content: center;
}

.ai-center {
  align-items: center;
}

.main_img {
  width: 13px;
  height: 13px;
}

.list-detail {
  width: 100%;
  height: 100%;
  background-color: #fff;

  .btn {
    width: 100%;
    text-align: right;
    margin-bottom: 10px;
  }

  .flex {
    display: flex;
  }

  .space-between {
    justify-content: space-between;
  }

  .list-main {
    height: 100%;

    .left {
      flex: 1;

      .main-table {
        width: 100%;
        max-height: 82vh;
        overflow-y: auto;
        border: 2px solid #000;
        padding: 10px 6px;
        background-color: #f5f7f9;

        .title1 {
          height: 70px;
          color: #000;
          display: flex;
          justify-content: center;
          align-items: center;
          background-color: #edf1fc;
          margin: 15px 0;
          font-size: 20px;
        }
      }
    }

    .right {
      width: 500px;
      border: 1px solid #ccc;
    }
  }
}

:deep(.ivu-cell-label) {
  line-height: 1.2;
  font-size: 15px;
  color: #808695;
}

.ml-20 {
  margin-left: 20px;
}

.valbox {
  flex: 1;
  border-bottom: 1px solid;
  padding-left: 2px;
  text-align: left;
  background-color: #fff;
  padding-left: 5px;
}

/deep/ .ivu-form-item-error-tip {
  padding-top: 2px;
}

/deep/.dd .ivu-form-item-content {
  margin-left: 0 !important;
}

/deep/.ivu-row .cc .table_border_class .ivu-form-item-content {
  margin-left: 160px !important;
}

.underline {
  text-decoration: underline;
  text-underline-offset: 0.5em;
}

/* styles.css */
td {
  padding: 5px;
  border: 1px solid #ccc;
}

/deep/.text-label {
  display: flex;
  align-items: center;
  padding: 0 5px;
  flex-basis: auto;
  width: auto;
}

.red {
  color: red;
  margin-right: 2px;
}

/deep/ .ivu-table .ivu-table-header th {
  background-color: #fff;
}

.row-border {
  border: 1px solid #ccc;
  padding: 10px 5px;
  box-sizing: border-box;
}

.no-padding {
  padding: 0;
}

.border-bottom-none {
  border-bottom: none;
}

.border-right-none {
  border-right: none;
}

.opertion_list {
  border: 1px solid #000;
  padding: 20px;
  margin-bottom: 10px;
  overflow: visible;

  .action_box {
    width: 100%;
    height: 30px;
    display: flex;
    justify-content: space-between;

    .choose_box {
      height: 30px;
      width: 70px;
      display: flex;
    }

    .other_box,
    .other_box1 {
      flex: 1;
      height: 30px;
      border: 1px dashed #5b9bd5;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
    }

    .other_box1 {
      border: 1px dashed #ff6347;
    }
  }
}

.table_border_class {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  text-align: center;
}
.table-container {
  padding: 20px;
}
/deep/ .table-container .ivu-form-item-content {
  margin-left: 0 !important;
}

.my-table {
  width: 100%;
  border-collapse: collapse;
  background-color: #fff;
}

.my-table th,
.my-table td {
  border: 1px solid #ddd;
  padding: 10px;
  text-align: center;
  overflow: hidden;
}

.my-table th {
  background-color: #f4f4f4;
  font-weight: bold;
}

.my-table input {
  width: 100%;
  padding: 5px;
  border: 1px solid #ddd;
  border-radius: 4px;
  text-align: center;
}
.my-table tbody tr:hover {
  background-color: #ebf7ff;
}

.form-row {
  display: flex;
  align-items: flex-start;
  margin-bottom: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 2px solid;
  border-radius: 4px;
}

.red-group {
  border-color: red;
  margin-right: 16px;
}

.green-group {
  border-color: green;
}

.actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-left: 12px;
  gap: 4px;
}
</style>
